/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,Button,ScrollView} from 'react-native';
import { connect } from "react-redux";
import { bindActionCreators } from "redux";

import * as appActions from '../actions/appAction';
import { scaleSize } from '../utils/screen';
let db;
import {i18n} from '../i18n/index';
let isEn = false;
class App extends Component {
  componentWillMount(){
    console.log(this.props)
    console.log(i18n);
  }
  render() {
    let {app} = this.props;
    return (
      <ScrollView contentContainerStyle={styles.container}>
        <Text>{app.num}</Text>
        <Text>{i18n.t("appName")}</Text>
        <Button onPress = {()=>this.insert()} title = "insert"></Button>
        <Button onPress = {()=>this.select()} title = "select"></Button>
        <Button onPress = {()=>this.props.transcation()} title = "transcation"></Button>
        <Button onPress = {()=>this.test()} title = "test"></Button>
        <Button onPress = {()=>this.menu()} title = "menu"></Button>
        <Button onPress = {()=>this.login()} title = "login"></Button>
        <Button onPress = {()=>this.office()} title = "office"></Button>
        <View style = {styles.viewTest}></View>
      </ScrollView>
    );
  }
  test(){
    isEn = !isEn;
    i18n.locale = isEn?"zh":"en";
    this.props.changeNum();
  }
  componentWillMount(){
    // setInterval(()=>{
    //   this.insert();
    // },1);
  }
  office(){
    this.props.navigation.navigate("office");
  }
  menu(){
    this.props.navigation.navigate("menu");
  }
  login(){
    this.props.navigation.navigate("login");
  }
  insert(){
      this.$sqlite.executeSql("insert into settings (key,value) values (?,?)",["data",+new Date()],(data)=>{
        console.log(data)
      },(err)=>{
        console.log(err);
      })
  }
  select(){
    this.$sqlite.executeSql("select * from sqlite_master where type=\"table\";",[],(data)=>{
      console.log(data.rows.raw())
    },(err)=>{
      console.log(err);
    });
  }
}
export default connect(
  state => ({
      app: state.app
  }),
  dispatch => bindActionCreators(appActions, dispatch)
)(App);
const styles = StyleSheet.create({
  container: {
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  viewTest:{
    width:scaleSize(2048),
    height:scaleSize(1536),
    backgroundColor: "red",
  }
});
